#ifndef __TYPES_H__
#define __TYPES_H__

#define BOOL_TRUE                        1
#define BOOL_FALSE                       0

typedef char                             CHAR;
typedef unsigned char                    UCHAR;
typedef unsigned char                    UINT8;
typedef short                            SHORT;
typedef short                            INT16;
typedef unsigned short                   USHORT;
typedef unsigned short                   UINT16;
typedef int                              INT32;
typedef unsigned int                     UINT32;
typedef long                             LONG;
typedef unsigned long                    ULONG;
typedef long long                        INT64;
typedef unsigned long long               UINT64;
typedef float                            FLOAT;
typedef double                           DOUBLE;
typedef ULONG                            BOOL;
typedef void                             VOID;

/*define function paramater in/out type */
#define IN
#define OUT
#define INOUT
#define UNUSED_PARAM(x)                  (VOID)x;

/* define string len */
#define STRING_LEN_8                     8
#define STRING_LEN_16                    16
#define STRING_LEN_32                    32
#define STRING_LEN_64                    64
#define STRING_LEN_128                   128
#define STRING_LEN_256                   256
#define STRING_LEN_512                   512
#define STRING_LEN_1024                  1024
#define STRING_LEN_2048                  2048
#define STRING_LEN_4096                  4096
#define STRING_LEN_8192                  8192

#ifndef UNUSED_PARAM 
#define UNUSED_PARAM(v)                 (void)(v) 
#endif 

#define NANO                            0
#define ERROR                           1
#define WARN                            2
#define INFO                            3
#define DEBUG                           4

#define DEBUG_LEVEL			WARN

#define PRINT(level, fmt, ...)          \
do                                      \
{                                       \
    if (level <= DEBUG_LEVEL)           \
        printf("<"#level"> [%s %d] :"fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
} while (0);

#define LOG_E(fmt, ...)                 PRINT(ERROR, fmt, ##__VA_ARGS__)
#define LOG_W(fmt, ...)                 PRINT(WARN, fmt, ##__VA_ARGS__)
#define LOG_I(fmt, ...)                 PRINT(INFO, fmt, ##__VA_ARGS__)
#define LOG_D(fmt, ...)                 PRINT(DEBUG, fmt, ##__VA_ARGS__)

typedef enum _SOFT_STAT_E_
{
    /* common fail: 0x00 ~ 0x0F */
    STAT_SUCCEED                        = 0x00000000,
    STAT_ERR_INVAILD_PARAM,
    STAT_ERR_MALLOC,
    STAT_ERR_CALLOC,
    STAT_ERR_FTOK,

    /* UART error: 0x50 ~ 0x5F */
    STAT_ERR_UART_WRITE                 = 0x00000010,
    STAT_ERR_UART_CFG,
    STAT_ERR_UART_TYPE,
    STAT_ERR_UART_ADD,

    STAT_ERR_I2C_BUSY,

    /* File error: 0x20 ~ 0x2F */
    STAT_ERR_FILE_OPEN                  = 0x00000020,
    STAT_ERR_FILE_CREAT,
    STAT_ERR_FILE_CLOSE,
    STAT_ERR_FILE_SEEK,
    STAT_ERR_FILE_WRITE,
    STAT_ERR_FILE_READ,
    STAT_ERR_FILE_TCGET,
    STAT_ERR_FILE_TCSET,
    STAT_ERR_FILE_FCNTL,

    /* socket error: 0x30 ~ 0x3F */
    STAT_ERR_SOCK_TYPE                  = 0x00000030,
    STAT_ERR_SOCK_CREAT,
    STAT_ERR_SOCK_CLOSE,
    STAT_ERR_SOCK_WRITE,
    STAT_ERR_SOCK_READ,
    STAT_ERR_SOCK_CONNECT,
    STAT_ERR_SOCK_BIND,
    STAT_ERR_SOCK_LISTEN,
    STAT_ERR_SOCK_ACCEPT,
    STAT_ERR_SOCK_IPADDR,
    STAT_ERR_SOCK_SETOPT,
    STAT_ERR_SOCK_PTON,

    /* system v error: 0x40 ~ 0x4F */
    STAT_ERR_SYSTEM_V_SHMGET            = 0x00000040,
    STAT_ERR_SYSTEM_V_SHMAT,
    STAT_ERR_SYSTEM_V_SHMDT,
    STAT_ERR_SYSTEM_V_SHM_RMID,
    STAT_ERR_SYSTEM_V_MSGGET,
    STAT_ERR_SYSTEM_V_MSG_SEND,
    STAT_ERR_SYSTEM_V_MSG_RECV,
    STAT_ERR_SYSTEM_V_MSG_RMID,
    STAT_ERR_SYSTEM_V_SEMGET,
    STAT_ERR_SYSTEM_V_SEM_INIT,
    STAT_ERR_SYSTEM_V_SEM_OPTION,

    /* IO multi error: 0x50 ~ 0x5F */
    STAT_ERR_SELECT                     = 0x00000050,
    STAT_ERR_SELECT_TIMEOUT,
    STAT_ERR_SELECT_CHECK,
    STAT_ERR_SELECT_NO_DATA,

    STAT_ERR_THREAD_CREATE              = 0x00000060,
    STAT_ERR_THREAD_DETACH,
    STAT_ERR_THREAD_TRY_LOCK,

    STAT_ERR_XML_LOAD                   = 0x00000070,
    STAT_ERR_XML_SAVE,
    STAT_ERR_XML_NONEXIT,
    STAT_ERR_XML_SET_ATTR,
    STAT_ERR_XML_SET_CDATA,
    STAT_ERR_XML_SET_OPAQUE,
    STAT_ERR_XML_SET_ELEMENT,
    STAT_ERR_XML_NEW_ATTR,
    STAT_ERR_XML_NEW_CDATA,
    STAT_ERR_XML_NEW_ELEM,
    STAT_ERR_XML_NEW_OPAQUE,

    STAT_ERR_TIMER_POOL_CREATE          = 0x00000080,
    STAT_ERR_DIR_NOT_EXIST,
    STAT_ERR_DIR_CREAT,
    STAT_ERR_DIR_OPEN,
    STAT_ERR_DIR_GETPWD,
    STAT_ERR_DIR_CHANGE,

    STAT_ERR_QUEUE_FULL,
    STAT_ERR_QUEUE_EMPTY,

    STAT_END                            = 0xFFFFFFFF,
}SOFT_STAT_e;

#endif

